{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Hive import Hive\n",
    "from EyerissF import EyerissF as EF\n",
    "import numpy as np\n",
    "import Extension\n",
    "import skimage.io as io\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "ef = EF()\n",
    "hive = Hive(ef,mode=\"manual\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "pics = [255-io.imread(\"Pic/01.png\", as_grey=True)]\n",
    "flts = [np.load(\"ConvLayerFilter/ConvLayer1Filter\"+str(x)+\".npy\") for x in range(1,7)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "pics=hive.Compress(pics)\n",
    "flts=hive.Compress(flts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "hive.input(pics, flts, 1, 6)\n",
    "hive.Conv2LogicalMapping()\n",
    "hive.Conv2PhysicalMapping()\n",
    "hive.Conv2d()\n",
    "hive.Reverse()\n",
    "pics=hive.Output()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "pics=hive.Pooling(hive.Decompress(pics),255)\n",
    "flts=[np.load(\"ConvLayerFilter/ConvLayer2Filter\"+str(x)+\".npy\") for x in range(1,17)]\n",
    "pics=hive.Compress(pics)\n",
    "flts=hive.Compress(flts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "r=[]\n",
    "for x in range(16):\n",
    "    hive.input(pics, list([flts[x]]), 6, 1)\n",
    "    hive.Conv2LogicalMapping()\n",
    "    hive.Conv2PhysicalMapping()\n",
    "    hive.Conv2d()\n",
    "    hive.Reverse()\n",
    "    r.append(hive.Output())\n",
    "\n",
    "pics = [Extension.NumpyAddExtension(hive.Decompress(r[x])) for x in range(16)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "pics=hive.Pooling(pics,255)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "vector = hive.FullConnect(np.array(pics).flatten(),np.load('FullConnectLayer/FullConnectLayer1.npy'),255)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "vector = hive.FullConnect(vector, np.load('FullConnectLayer/FullConnectLayer2.npy'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "vector = hive.FullConnect(vector, np.load('FullConnectLayer/FullConnectLayer3.npy'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "vector=vector.reshape(1,vector.size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "this number is :  2\n"
     ]
    }
   ],
   "source": [
    "print(\"this number is : \",vector.argmax())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
